.TH std::reference_converts_from_temporary 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::reference_converts_from_temporary \- std::reference_converts_from_temporary

.SH Synopsis
   Defined in header <type_traits>
   template< class T, class U >               (since C++23)
   struct reference_converts_from_temporary;

   Let V be std::remove_cv_t<U> if U is a scalar type or cv void, or U otherwise. If T
   is a reference type, and given a hypothetic expression e such that decltype(e) is V,
   the variable definition T ref = e; is well-formed and binds a temporary object to
   ref, then provides the member constant value equal to true. Otherwise, value is
   false.

   If T is an lvalue reference type to a const- but not volatile-qualified object type
   or an rvalue reference type, both std::remove_reference_t<T> and
   std::remove_reference_t<U> shall be complete types, cv void, or an arrays of unknown
   bound; otherwise the behavior is undefined.

   If an instantiation of a template above depends, directly or indirectly, on an
   incomplete type, and that instantiation could yield a different result if that type
   were hypothetically completed, the behavior is undefined.

   If the program adds specializations for std::reference_converts_from_temporary or
   std::reference_converts_from_temporary_v, the behavior is undefined.

.SH Member constants

            true if T is a reference type, a U value can be bound to T in
   value    copy-initialization, and a temporary object would be bound to the
   \fB[static]\fP reference, false otherwise
            \fI(public static member constant)\fP

.SH Member functions

   operator bool converts the object to bool, returns value
                 \fI(public member function)\fP
   operator()    returns value
   \fI(C++14)\fP       \fI(public member function)\fP

.SH Member types

   Type       Definition
   value_type bool
   type       std::integral_constant<bool, value>

.SH Notes

   std::reference_converts_from_temporary can be used for rejecting some cases that
   always produce dangling references.

.SH Example


// Run this code

 #include <type_traits>

 int main() {}

 static_assert(std::reference_converts_from_temporary_v<int&&, int> == true);
 static_assert(std::reference_converts_from_temporary_v<const int&, int> == true);
 static_assert(std::reference_converts_from_temporary_v<int&&, int&&> == false);
 static_assert(std::reference_converts_from_temporary_v<const int&, int&&> == false);
 static_assert(std::reference_converts_from_temporary_v<int&&, long&&> == true);
 static_assert(std::reference_converts_from_temporary_v<int&&, long> == true);

.SH See also

   is_convertible
   is_nothrow_convertible checks if a type can be converted to the other type
   \fI(C++11)\fP                \fI(class template)\fP
   (C++20)
   invoke                 invokes any Callable object with given arguments
   invoke_r               and possibility to specify return type
   \fI(C++17)\fP                (since C++23)
   (C++23)                \fI(function template)\fP
   bind                   binds one or more arguments to a function object
   \fI(C++11)\fP                \fI(function template)\fP
   visit                  calls the provided functor with the arguments held by one or
   \fI(C++17)\fP                more variants
                          \fI(function template)\fP
   constructor            constructs a new std::function instance
                          \fI(public member function of std::function<R(Args...)>)\fP
   constructor            constructs a new std::move_only_function object
   (C++23)                \fI(public member function of std::move_only_function)\fP
                          constructs the task object
   constructor            \fI(public member function of std::packaged_task<R(Args...)>)\fP

